home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Translators / TMCallback.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  9.4 KB  |  303 lines

  1. //SHARE-IN-MEMORY=true
  2. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  3.  
  4. ///////////////////////////////////////////////// Global Identifiers //////////////////////////////////////////////////////
  5. var PTYPE_DIRECTIVE = 0;
  6. var PTYPE_TEXT = 1;
  7. var PTYPE_ATTRIBUTE = 2;
  8. var PTYPE_TAG = 3;
  9. var debugTMC = false;
  10.  
  11. ////////////////////////////////////////////////// TMCallback Class ///////////////////////////////////////////////////////
  12.  
  13. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. // Function : TMCallback::TMCallback
  15. // Purpose    : translation manager's JavaScript callback object passed to dreamweaver.scanSourceString.
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. function TMCallback(transMgr)
  18. {
  19.     // Members
  20.     this.transMgr = transMgr;
  21.     this.inTagSpan = false;
  22.     this.withinCFOutput = false;
  23.     this.inCData = 0;
  24. }
  25.   // methods
  26.   TMCallback.prototype.directive = directive;
  27.   TMCallback.prototype.text = text;
  28.   TMCallback.prototype.attribute = attribute;
  29.   TMCallback.prototype.openTagBegin = openTagBegin;
  30.   TMCallback.prototype.openTagEnd = openTagEnd;
  31.   TMCallback.prototype.closeTagBegin = closeTagBegin;
  32.   TMCallback.prototype.closeTagEnd = closeTagEnd;
  33.   TMCallback.prototype.restartParse = restartParse;
  34.   TMCallback.prototype.xmlCDataStartTag = xmlCDataStartTag;
  35.   TMCallback.prototype.xmlCDataEndTag = xmlCDataEndTag;
  36.  
  37. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. // Function : TMCallback::directive
  39. // Purpose    : called for every directive within the document being parsed
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. function directive(code, offset)
  42. {
  43.     if (this.inCData > 0)
  44.         return true;
  45.  
  46.     if (debugTMC)
  47.         alert("directive\n" + code);
  48.     this.transMgr.notifyTagBegin("", offset);
  49.     if (this.inTagSpan)
  50.     {
  51.         this.transMgr.addToTagSpan(code, offset, true);
  52.     }
  53.     else
  54.     {
  55.         var part = this.transMgr.getParticipant(PTYPE_DIRECTIVE, code);
  56.         var trans = this.transMgr.getData(part, code);
  57.         this.transMgr.translateDirective(code, offset, trans);
  58.     }
  59.           
  60.     return true;
  61. }
  62.  
  63. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  64. // Function : TMCallback::attribute
  65. // Purpose    : called for every attribute within the document being parsed
  66. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67. function attribute(name, code)
  68. {
  69.     if (this.inCData > 0)
  70.         return true;
  71.  
  72.     if (debugTMC)
  73.         alert("attribute\n" + code);
  74.     if (this.withinCFOutput && name.toLowerCase() == "query")
  75.     {
  76.         if (!this.transMgr.CFOutput.IsEmpty())
  77.         {
  78.             var queryName = this.transMgr.CFOutput.Pop();
  79.             queryName = code;
  80.             this.transMgr.CFOutput.Push(queryName);
  81.         }
  82.     }
  83.     if (!this.inTagSpan)
  84.     {
  85.         var part = null;
  86.         if (this.transMgr.lookInThisAttribute(code))
  87.         {
  88.             part = this.transMgr.getParticipant(PTYPE_ATTRIBUTE, code, name);
  89.             var trans = this.transMgr.getData(part, code, name);
  90.             this.transMgr.translateAttribute(code, name, trans);
  91.         }
  92.         else
  93.         {
  94.             this.transMgr.translateAttribute(code, name, null);
  95.         }
  96.     }
  97.  
  98.     return true;
  99. }
  100.  
  101. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. // Function : TMCallback::text
  103. // Purpose    : called for every text span within the document being parsed
  104. //              calls translateText for each occurence of pattern within the text run 
  105. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. function text(code, offset)
  107. {
  108.     if (this.inCData > 0)
  109.         return true;
  110.  
  111.     if (debugTMC)
  112.         alert("text\n" + code);
  113.     this.transMgr.notifyTagBegin("", offset);
  114.     
  115.     if (this.inTagSpan)
  116.     {
  117.         this.transMgr.addToTagSpan(code, offset, true);
  118.     }
  119.     else
  120.     {      
  121.         this.transMgr.translateTextSpan(code, offset);
  122.     }
  123.  
  124.     return true;
  125. }
  126.  
  127. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  128. // Function : TMCallback::openTagBegin
  129. // Purpose    : called whenever an open tag is detected within the document being parsed
  130. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  131. function openTagBegin(tag, offset)
  132. {
  133.     if (this.inCData > 0)
  134.         return true;
  135.  
  136.     this.transMgr.notifyTagBegin(tag, offset);
  137.     if (this.transMgr.lookInThisTag(tag.toLowerCase()))
  138.     {
  139.         if (tag.toLowerCase() == "cfoutput")
  140.         {
  141.             this.withinCFOutput = true;
  142.             this.transMgr.CFOutput.Push("");
  143.         }
  144.     }
  145.     if (tag == "mm:invisible")
  146.     {
  147.         this.transMgr.setDecoration(false);
  148.     }
  149.  
  150.     return true;
  151. }
  152.  
  153. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  154. // Function : TMCallback::openTagEnd
  155. // Purpose    : called whenever an open tag is ended within the document being parsed
  156. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. function openTagEnd(offset, trailingFormat)
  158. {
  159.     if (this.inCData > 0)
  160.         return true;
  161.  
  162.     var code = this.transMgr.notifyTagEnd(offset);
  163.     if (debugTMC)
  164.         alert("open tag\n" + code);
  165.     if (this.inTagSpan)
  166.     {
  167.         this.transMgr.addOpenTagToTagSpan(code, offset, trailingFormat);
  168.     }
  169.     else if (this.transMgr.lookInThisTag(this.transMgr.getCurrentTagName()))
  170.     {
  171.         if (this.withinCFOutput)
  172.         {
  173.             this.withinCFOutput = false;
  174.         }
  175.  
  176.         // Try to translate this as a tag span
  177.         var success = false;
  178.         this.inTagSpan = this.transMgr.translateTagSpan(code, offset, trailingFormat);
  179.         if (this.inTagSpan)
  180.         {
  181.             // Try to add the first open tag to the tag span.  If this tag
  182.             // has the form <.../>, the tag span will complete.  If addOpenTag
  183.             // returns false, it means that the tag span completed but no match
  184.             // was found.
  185.             var result = this.transMgr.addOpenTagToTagSpan(code, offset, trailingFormat);
  186.             success = result.success;
  187.             this.inTagSpan = result.inTagSpan;
  188.             if (result.reparse)
  189.                 return false;
  190.         }
  191.  
  192.         // If we didn't end up in a tag span (or the entire tag span was
  193.         // a single <.../> tag which didn't match any of the patterns).
  194.         if (!this.inTagSpan && !success)
  195.         {
  196.             var part = this.transMgr.getParticipant(PTYPE_TAG, code);
  197.             var trans = this.transMgr.getData(part, code);
  198.             var startOffset = this.transMgr.getCurrentTagOffset();
  199.             this.transMgr.translateTag(code, startOffset, trans);
  200.         }
  201.     }
  202.     else
  203.     {
  204.         var startOffset = this.transMgr.getCurrentTagOffset();
  205.         this.transMgr.translateTag(code, startOffset, null);
  206.     }
  207.  
  208.     this.transMgr.pushOpenTag(trailingFormat);
  209.     return true;
  210. }
  211.  
  212. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  213. // Function : TMCallback::closeTagBegin
  214. // Purpose    : called whenever a close tag is detected within the document being parsed
  215. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  216. function closeTagBegin(tag, offset)
  217. {
  218.     if (this.inCData > 0)
  219.         return true;
  220.  
  221.     this.transMgr.notifyTagBegin(tag, offset);
  222.     if (this.transMgr.lookInThisTag(tag.toLowerCase()))
  223.     {
  224.         if (tag.toLowerCase()== "cfoutput")
  225.         {
  226.             if (!this.transMgr.CFOutput.IsEmpty())
  227.             {
  228.                 var queryName = this.transMgr.CFOutput.Pop();
  229.             }
  230.         }
  231.     }
  232.     if (tag == "mm:invisible")
  233.     {
  234.         this.transMgr.setDecoration(true);
  235.     }
  236.  
  237.     return true;
  238. }
  239.  
  240. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  241. // Function : TMCallback::closeTagEnd
  242. // Purpose    : called whenever a close tag is ended within the document being parsed
  243. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  244. function closeTagEnd(offset)
  245. {
  246.     if (this.inCData > 0)
  247.         return true;
  248.  
  249.     var code = this.transMgr.notifyTagEnd(offset);
  250.     if (debugTMC)
  251.         alert("close tag\n" + code);
  252.     this.transMgr.popCloseTag();
  253.     if (this.inTagSpan)
  254.     {
  255.         // Try to add this close tag to the tag span.  If this tag ends
  256.         // the tag span, this.transMgr.inTagSpan will change to false.
  257.         // If addCloseTag returns false, it means that the tag span
  258.         // completed, but no match was found.  This means we have to
  259.         // restart the parse.
  260.         var result = this.transMgr.addCloseTagToTagSpan(code, offset);
  261.         this.inTagSpan = result.inTagSpan;
  262.         if (result.reparse)
  263.             return false;
  264.     }
  265.     else if (this.transMgr.lookInThisTag(this.transMgr.getCurrentTagName()))
  266.     {
  267.         if (!this.inTagSpan)
  268.         {
  269.             var part = this.transMgr.getParticipant(PTYPE_TAG, code);
  270.             var trans = this.transMgr.getData(part, code);
  271.             var startOffset = this.transMgr.getCurrentTagOffset();
  272.             this.transMgr.translateTag(code, startOffset, trans);
  273.         }
  274.     }
  275.     else
  276.     {
  277.         var startOffset = this.transMgr.getCurrentTagOffset();
  278.         this.transMgr.translateTag(code, startOffset, null);
  279.     }
  280.  
  281.     return true;
  282. }
  283.  
  284.  
  285. function restartParse()
  286. {
  287.     this.transMgr.initialize();
  288.     return false;
  289. }
  290.  
  291.  
  292. function xmlCDataStartTag()
  293. {
  294.     this.inCData++;
  295.     return true;
  296. }
  297.  
  298. function xmlCDataEndTag()
  299. {
  300.     if (this.inCData > 0)
  301.         this.inCData--;
  302.     return true;
  303. }